Skip to content

Conversation

@n-p-soft
Copy link
Contributor

@n-p-soft n-p-soft commented Nov 12, 2025

Due to two typos, midi_poll was always failing, as the 'revents' field was not properly set.
Signed-off-by: Nicolas Provost [email protected]

@github-actions
Copy link

github-actions bot commented Nov 12, 2025

Thank you for taking the time to contribute to FreeBSD!
There is an issue that needs to be fixed:

  • Real email address is needed (53f4ff4)

Please review CONTRIBUTING.md, then update and push your branch again.

@markjdb
Copy link
Member

markjdb commented Nov 16, 2025

@christosmarg could you please take a look at this? The patch seems obviously right. The commit log message needs to be fixed up a little.

@gmshake
Copy link
Contributor

gmshake commented Nov 16, 2025

I think the fix is right. Ref: the very first version of the midi.c from NetBSD [1].

[1] NetBSD/src@48bae9e#diff-dadfe9a149c74b946edbe5f3764799be7ba664df592dcc04bef1d70f003a2a10

mtx_unlock(&m->qlock);

return (revents);
return (revents ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to return revents as it is? Why are you returning a bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must check that. The generic poll system call returns the count of file descriptors having matching events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what's returned to usersland by poll(2), but the kernel poll() methods return event bitmasks.

@christosmarg
Copy link
Contributor

The change is good. Can you please combine those into one commit and rebase on top main?

events |= events & (POLLOUT | POLLWRNORM);
revents |= events & (POLLOUT | POLLWRNORM);

if (revents == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so (for now).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about the revents == 0. Before, because of the bug, this would always be true, but now it won't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right; I think this block should be split to handle the case when both POLLIN and POLLOUT are passed. Just updated the code.

Copy link
Contributor Author

@n-p-soft n-p-soft Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I missed this problem because I focused on the locks.. I can tell you that I removed 'qlock' from midi.c entirely and I'm currently testing it (on 13.5, as I cannot manage to compile main).

}

mtx_unlock(&m->lock);
mtx_unlock(&m->qlock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the patch, but I'm pretty sure there is a lock order reversal here. Have you tested this code path? If there is, I can propose a patch. Let me know.

Copy link
Contributor Author

@n-p-soft n-p-soft Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just swapped these unlocks, seems strange to me. Anyway let restore the right order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can open a new PR for this issue.

@christosmarg
Copy link
Contributor

freebsd-git pushed a commit that referenced this pull request Nov 24, 2025
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	christos
Pull Request:	#1887
Due to two typos, midi_poll was always failing, as the 'revents' field was not properly set.

Signed-off-by: Nicolas Provost <[email protected]>
freebsd-git pushed a commit that referenced this pull request Nov 28, 2025
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	christos
Pull Request:	#1887

(cherry picked from commit 8f8b8e4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants